//
//  YMContent.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/4/15.
//

import UIKit
import HandyJSON

struct YMContent: HandyJSON,Hashable {
    var bookId   :String = ""
    var chapterId:String = ""
    var title    :String = ""
    var content  :String = ""
    var created  :String = ""
    var updated  :String = ""
    
    var isVip    :Bool = false
    var getContent :String{
        return removeLine(content:content)
    }
    func removeLine(content:String) ->String{
        var datas : NSArray = content.components(separatedBy: CharacterSet.newlines) as NSArray;
        let pre = NSPredicate(format:"self <> ''");
        datas = datas.filtered(using: pre) as NSArray
        var list : [String] = [];
        datas.forEach { (object) in
            if let str = object as? String{
                let strName = str.trimmingCharacters(in: .whitespacesAndNewlines)
                if strName.count > 0 {
                    let emptyData = "\u{3000}" + "\u{3000}" + strName
                    list.append(emptyData)
                }
            }
        }
        return list.joined(separator: "\n");
    }
    mutating func mapping(mapper: HelpingMapper) {
        mapper <<< self.chapterId <-- ["chapterId","id",]
        mapper <<< self.content   <-- ["cpContent","body","content"]
    }
}
